package shmged.com.shlcm.utils;

import java.util.ArrayList;
import java.util.List;

import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.org.WTGroup;
import wt.org.WTOrganization;
import wt.org.WTUser;
import wt.query.QueryException;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.util.WTException;

public class CmWTUserUtil {
/*
	public static WTUser gerWTUserByNumber(String num){
		WTUser user=null;
		try {
			QuerySpec qs=new QuerySpec(WTUser.class);
			if(!num.equals("")&&num!=null)
			{
				qs.appendWhere(new SearchCondition(WTUser.class,WTUser,SearchCondition.EQUAL,name));
			}
			QueryResult qr=PersistenceHelper.manager.find(qs);
			while(qr.hasMoreElements())
			{
				user=(WTUser)qr.nextElement();
			}
		} catch (QueryException e) {
			e.printStackTrace();
		} catch (WTException e) {
			e.printStackTrace();
		}
		return user;
	}*/
	
	public static WTUser getWTUserByName(String name)
	{
		WTUser user=null;
		try {
			QuerySpec qs=new QuerySpec(WTUser.class);
			if(!name.equals("")&&name!=null)
			{
				qs.appendWhere(new SearchCondition(WTUser.class,WTUser.NAME,SearchCondition.EQUAL,name));
			}
			QueryResult qr=PersistenceHelper.manager.find(qs);
			while(qr.hasMoreElements())
			{
				user=(WTUser)qr.nextElement();
			}
		} catch (QueryException e) {
			e.printStackTrace();
		} catch (WTException e) {
			e.printStackTrace();
		}
		return user;
	}
	
	
	
	public static List getAllUser()
	{
		List userList=new ArrayList();
		try {
			QuerySpec qs=new QuerySpec(WTUser.class);
			QueryResult qr=PersistenceHelper.manager.find(qs);
			while(qr.hasMoreElements())
			{
				WTUser user=(WTUser)qr.nextElement();
				userList.add(user);
			}
		} catch (QueryException e) {
			e.printStackTrace();
		} catch (WTException e) {
			e.printStackTrace();
		}
		return userList;
	}
	
	public static List getAllGroups(){
		List groupList=new ArrayList();
		try {
			QuerySpec qs=new QuerySpec(WTGroup.class);
			QueryResult qr=PersistenceHelper.manager.find(qs);
			while(qr.hasMoreElements())
			{
				WTGroup group=(WTGroup)qr.nextElement();
				groupList.add(group);
			}
		} catch (QueryException e) {
			e.printStackTrace();
		} catch (WTException e) {
			e.printStackTrace();
		}
		return groupList;
	}
	public static List getAllOrganization(){
		List organizationList=new ArrayList();
		try {
			QuerySpec qs=new QuerySpec(WTOrganization.class);
			QueryResult qr=PersistenceHelper.manager.find(qs);
			while(qr.hasMoreElements())
			{
				WTOrganization organization=(WTOrganization)qr.nextElement();
				organizationList.add(organization);
			}
		} catch (QueryException e) {
			e.printStackTrace();
		} catch (WTException e) {
			e.printStackTrace();
		}
		return organizationList;
	}
}
